 <!-- 病虫害记录 -->
<template>
  <BaseMainSlot>
    <template v-slot:btn-box>
      <SelectButton
        :buttonselectlist="buttonselectlist"
        @nowselectbuttonindex="batchstaumet"
      />
      <ActionBar
        :page-no="29"
        :add-active="addActive"
        :del-active="delActive"
        :has-cancel="false"
        :has-edit="false"
        :has-del="false"
        :has-edit-column="true"
        :has-export="searchlist.result == 1"
        @showColumn="showColumn"
        @download="download"
        @add="add"
        @del="delList"
      />
    </template>
    <template v-slot:search-box>
      <SearchForm
        :form-config="formConfig"
        :form-data="searchlist"
        @search="search"
      />
    </template>
    <template v-slot:table-box>
      <Table
        v-loading="loading"
        :prop-list="tableColumn"
        :list-data="tableData"
        :show-select-column="false"
        @sortChange="changeTableSort"
      >
        <!-- 时间 -->
        <template v-slot:insectDate="{ row }">
          <template v-if="row.alarmBatchNo">
            {{ row.insectDate }}
          </template>
        </template>
        <!-- 查看设施  -->
        <template v-slot:facilityNoList="{ row }">
          <template v-if="row.alarmBatchNo">
            <el-button
              class="text-btn-cursor"
              type="text"
              size="small"
              @click="checkFacility(row)"
            >
              <i class="el-icon-view"></i> 查看
            </el-button>
          </template>
        </template>
        <!-- 查看编号 -->
        <template v-slot:IdNameList="{ row }">
          <template v-if="row.alarmBatchNo">
            <el-button
              class="text-btn-cursor"
              type="text"
              size="small"
              @click="seeIdNameList(row)"
            >
              <i class="el-icon-view"></i> 查看
            </el-button>
          </template>
        </template>
        <!-- 操作 -->
        <template v-slot:operation="{ row }">
          <template v-if="row.alarmBatchNo">
            <el-button
              v-if="searchlist.result === 2"
              class="text-btn-cursor"
              type="text"
              size="small"
              @click="handleEdit(row)"
            >
              修改
            </el-button>
            <el-button
              v-if="row.alarmBatchNo"
              class="text-btn-cursor cursor-delete"
              type="text"
              size="small"
              @click="delSingle(row)"
            >
              <i class="el-icon-delete"></i> 删除
            </el-button>
          </template>
        </template>
        <!-- 处理详情 -->
        <template v-slot:lookInfo="{ row }">
          <template v-if="row.alarmBatchNo">
            <el-button
              class="text-btn-cursor"
              type="text"
              size="small"
              @click="lookInfo(row)"
            >
              点击查看
            </el-button>
          </template>
        </template>
        <!-- 查看图片 -->
        <template v-slot:lookPicture="{ row }">
          <template v-if="row.alarmBatchNo">
            <el-button
              class="text-btn-cursor"
              type="text"
              size="small"
              @click="lookPicture(row)"
            >
              点击查看
            </el-button>
          </template>
        </template>
      </Table>
      <Pagination
        :page-size="pageSize"
        :current-page="currentPage"
        :total-size="totalSize"
        @changePageSize="changePageSize"
        @changeCurrentPage="changeCurrentPage"
      />
    </template>
    <template v-slot:dialog>
      <!-- 添加 -->
      <el-dialog
        :title="`病虫害记录`"
        :visible.sync="isShow"
        @close="addCancel"
      >
        <el-form
          ref="addFormData"
          label-position="left"
          :model="addFormData"
          :rules="rules"
        >
          <el-form-item label="批次名称:" prop="batchNo" class="w50p">
            <el-select
              v-model="addFormData.batchNo"
              clearable
              filterable
              @change="batch"
            >
              <el-option
                v-for="item in batchList"
                :key="item.batchNo"
                :label="item.batchName"
                :value="item.batchNo"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="设施名称:" prop="facilityNoList" class="w50p">
            <el-select
              v-model="addFormData.facilityNoList"
              multiple
              filterable
              clearable
            >
              <el-option
                v-for="(item, index) in facilityLists"
                :key="index"
                :label="item.facilityName"
                :value="item.facilityNo"
              />
            </el-select>
          </el-form-item>
          <!-- TODO:修改 -->
          <el-form-item label="编号名称:" prop="batchSingleNos" class="w50p">
            <el-select
              v-model="addFormData.batchSingleNos"
              multiple
              filterable
              clearable
            >
              <el-option
                v-for="(item, index) in idList"
                :key="index"
                :label="item"
                :value="item"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="病虫害类别:" prop="alarmTypeName" class="w50p">
            <el-select
              v-model="addFormData.alarmTypeName"
              clearable
              filterable
              @change="queryAlarmName"
            >
              <el-option
                v-for="item in alarmTypeList"
                :key="item.value"
                :label="item.name"
                :value="item.name"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="病虫害名称:" prop="alarmDes" class="w50p">
            <el-select v-model="addFormData.alarmDes" clearable filterable>
              <el-option
                v-for="item in alarmDesList"
                :key="item.insectId"
                :label="item.name"
                :value="item.name"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="备注:" prop="remark" class="w50p">
            <el-input
              v-model="addFormData.remark"
              type="text"
              placeholder="请输入备注信息"
              clearable
            />
          </el-form-item>
          <el-form-item label="病虫害图片:" class="w100p">
            <ele-upload-image
              v-model="image2"
              :response-fn="handleResponse"
              :before-remove="handleRemove"
              :headers="headers"
              :file-size="10"
              :action="ImageUrl()"
            />
          </el-form-item>
          <el-form-item label="发现日期:" prop="insectDate" class="w50p">
            <el-date-picker
              v-model="addFormData.insectDate"
              type="datetime"
              value-format="timestamp"
              placeholder="请选择通知时间"
            />
          </el-form-item>
          <el-form-item label="处理人:" prop="disposeManNo" class="w50p">
            <el-select v-model="addFormData.disposeManNo" clearable>
              <el-option
                v-for="(item, index) in staffList"
                :key="index"
                :label="item.person.name"
                :value="item.personNo"
              />
            </el-select>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button class="zh-button-one" @click="addCancel">取 消</el-button>
          <el-button class="zh-button-two" type="primary" @click="addSaves()"
            >确 定</el-button
          >
        </span>
      </el-dialog>
      <!-- 列配置 -->
      <el-dialog
        id="tableColumnDialog"
        title="配置列"
        :visible.sync="dialogTableColumnVisible"
      >
        <tableColumn
          v-if="dialogTableColumnVisible"
          ref="tableColumn"
          :table-column="allTableColumn"
          @cancelColumn="cancelColumn"
        />
        <div slot="footer" class="dialog-footer">
          <el-button
            class="zh-button-one"
            @click="dialogTableColumnVisible = false"
          >
            取 消
          </el-button>
          <el-button class="zh-button-two" type="primary" @click="addSave">
            保 存
          </el-button>
        </div>
      </el-dialog>
      <!-- 查看设施 -->
      <el-dialog
        title="设施列表"
        :visible="facilityDialogVisible"
        :before-close="
          () => {
            facilityDialogVisible = false;
          }
        "
      >
        <div class="facility-list">
          <div
            v-for="(item, index) in batchFacilityMapperList"
            :key="index"
            class="facility-item"
          >
            <div class="info-line">
              <div class="name">设施编号：</div>
              <div class="value">{{ item.facilityNo }}</div>
            </div>
            <div class="info-line">
              <div class="name">设施名称：</div>
              <div class="value">{{ item.facilityName }}</div>
            </div>
          </div>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button
            class="zh-button-one"
            @click="facilityDialogVisible = false"
          >
            关 闭
          </el-button>
        </div>
      </el-dialog>
      <!-- 查看编号 -->
      <el-dialog
        title="单个编号"
        :visible.sync="showIdNameList"
        width="30%"
        class="dialogRec"
        @close="showIdNameList = false"
      >
        <div style="display: flex">
          <div v-for="(item, index) in singleNoList" :key="index">
            <div
              v-if="!!activeSingleNoList"
              class="IdNameList"
              :class="
                activeSingleNoList.includes(item)
                  ? 'IdNameList activeId'
                  : 'IdNameList'
              "
            >
              {{ item }}
            </div>
            <div v-else class="IdNameList">{{ item }}</div>
          </div>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button class="zh-button-one" @click="showIdNameList = false"
            >关 闭</el-button
          >
        </span>
      </el-dialog>
      <!-- 查看用药 -->
      <el-dialog
        title="设施列表"
        :visible="useMedicineVisible"
        :before-close="
          () => {
            useMedicineVisible = false;
          }
        "
      >
        <div class="facility-list">
          <div
            v-for="(item, index) in useMedicineList"
            :key="index"
            class="facility-item"
          >
            <div class="info-line">
              <div class="name">设施编号：</div>
              <div class="value">{{ item.facilityNo }}</div>
            </div>
            <div class="info-line">
              <div class="name">设施名称：</div>
              <div class="value">{{ item.facilityName }}</div>
            </div>
          </div>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button class="zh-button-one" @click="useMedicineVisible = false">
            关 闭
          </el-button>
        </div>
      </el-dialog>
      <!-- 查看图片 -->
      <el-dialog
        title="图片"
        :visible.sync="showpicview"
        width="55%"
        v-loading="imgloading"
      >
        <div
          style="
            width: 100%;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 20px;
          "
        >
          <img
            style="height: 100%"
            :src="`data:image/png;base64,${pictviewurl}`"
          />
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button class="zh-button-one" @click="showpicview = false"
            >取 消</el-button
          >
          <el-button
            class="zh-button-two"
            type="primary"
            @click="showpicview = false"
            >确 定</el-button
          >
        </span>
      </el-dialog>
      <!-- 查看详情 -->
      <el-dialog
        title="处理信息"
        :visible.sync="showInfo"
        v-loading="imgloading"
      >
        <div style="width: 100%; height: 100%">
          <div
            class="info"
            v-for="(item, index) in inputsRecordBOList"
            :key="index"
          >
            <div class="line">
              <div class="left">
                <div class="name">处理人：</div>
                <div class="value">{{ item.personName || undefined }}</div>
              </div>
              <div class="right">
                <div class="name">处理日期：</div>
                <div class="value">{{ item.assetDate || undefined }}</div>
              </div>
            </div>
            <div class="line">
              <div class="left">
                <div class="name">处理图片：</div>
                <div class="value" v-if="item.url">
                  <img :src="item.url" alt="" style="height: 100%" />
                </div>
              </div>
              <div class="right">
                <div class="name">备注：</div>
                <div class="value">{{ item.remark || undefined }}</div>
              </div>
            </div>
            <div class="line">
              <div class="left">
                <div class="name">治疗药物：</div>
                <div class="value">
                  {{ item.materialDTO.materialName || undefined }}
                </div>
              </div>
              <div class="right">
                <div class="name">投入量：</div>
                <div class="value">{{ item.assetQuantity || undefined }}</div>
              </div>
            </div>
          </div>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button class="zh-button-one" @click="showInfo = false"
            >取 消</el-button
          >
          <el-button
            class="zh-button-two"
            type="primary"
            @click="showInfo = false"
            >确 定</el-button
          >
        </span>
      </el-dialog>
    </template>
  </BaseMainSlot>
</template>

<script>
import SearchForm from "@/components/searchForm";
import Table from "@/components/table/table.vue";
import userApi from "@/api/user/index";
import ActionBar from "@/components/ActionBar";
import Pagination from "@/components/Pagination";
import pestInfoApi from "@/api/basic-info-manage/pest-info/index";
import BaseMainSlot from "@/components/BaseMainSlot/newBaseMainSlot.vue";
import SelectButton from "@/components/selectbutton/index.vue";
import { mymixin } from "@/utils/mixins";
import { mapGetters } from "vuex";
import { farmingTypeTitle } from "@/utils/validate";
import baseURL from "@/api/baseURL";
import danwei from "@/api/basic-info-manage/unit-manage/index";
// TODO:
import API from "@/api/digital-production/health-management/pest-record/index";
export default {
  name: "PestRecords",
  components: {
    SearchForm,
    Table,
    ActionBar,
    Pagination,
    BaseMainSlot,
    SelectButton,
  },
  mixins: [mymixin],
  data() {
    var farmingTypeTitles = farmingTypeTitle();
    return {
      // 药品
      materialNum: 1,
      materialNos: [],
      assetQuantity: [],
      exchangeRatio: [],
      exchangeUnitNo: [],
      unitlists: [], // 体积单位
      agriculturalMaterialList: [], // 药品列表
      staffList: [],
      buttonselectlist: [{ name: "未处理" }, { name: "已处理" }],
      tableColumn: [
        { prop: "alarmBatchName", label: "批次名称", minWidth: "180" },
        { prop: "alarmBatchNo", label: "批次号", minWidth: "120" },
        {
          prop: "facilityNoList",
          label: "发现设施",
          minWidth: "120",
          slotName: "facilityNoList",
        },
        {
          prop: "IdNameList",
          label: "患病个体",
          minWidth: "120",
          slotName: "IdNameList",
        },
        { prop: "alarmTypeName", label: farmingTypeTitles + "类别" },
        { prop: "alarmDes", label: farmingTypeTitles + "名称" },
        {
          prop: "lookPicture",
          label: "图片",
          minWidth: "120",
          slotName: "lookPicture",
        },
        {
          prop: "insectDate",
          label: "发现日期",
          slotName: "insectDate",
          width: "185",
        },
        {
          prop: "operation",
          label: "操作",
          slotName: "operation",
          width: "170",
        },
      ],
      tableColumn1: [
        { prop: "alarmBatchName", label: "批次名称", minWidth: "180" },
        { prop: "alarmBatchNo", label: "批次号", minWidth: "120" },
        {
          prop: "facilityNoList",
          label: "发现设施",
          minWidth: "120",
          slotName: "facilityNoList",
        },
        {
          prop: "IdNameList",
          label: "患病个体",
          minWidth: "120",
          slotName: "IdNameList",
        },
        { prop: "alarmTypeName", label: farmingTypeTitles + "类别" },
        { prop: "alarmDes", label: farmingTypeTitles + "名称" },
        {
          prop: "lookPicture",
          label: "图片",
          minWidth: "120",
          slotName: "lookPicture",
        },
        {
          prop: "insectDate",
          label: "发现日期",
          slotName: "insectDate",
          width: "185",
        },
        {
          prop: "operation",
          label: "操作",
          slotName: "operation",
          width: "170",
        },
      ],
      tableColumn2: [
        { prop: "alarmBatchName", label: "批次名称", minWidth: "180" },
        { prop: "alarmBatchNo", label: "批次号", minWidth: "120" },
        {
          prop: "facilityNoList",
          label: "发现设施",
          minWidth: "120",
          slotName: "facilityNoList",
        },
        {
          prop: "IdNameList",
          label: "患病个体",
          minWidth: "120",
          slotName: "IdNameList",
        },
        { prop: "alarmTypeName", label: farmingTypeTitles + "类别" },
        { prop: "alarmDes", label: farmingTypeTitles + "名称" },
        {
          prop: "lookPicture",
          label: "图片",
          minWidth: "120",
          slotName: "lookPicture",
        },
        {
          prop: "insectDate",
          label: "发现日期",
          slotName: "insectDate",
          width: "185",
        },
        {
          prop: "lookInfo",
          label: "处理详情",
          minWidth: "120",
          slotName: "lookInfo",
        },
      ],
      formConfig: [
        {
          label: "批次名称",
          prop: "alarmBatchNo",
          type: "select",
          options: [],
          optionKey: { label: "batchName", value: "batchNo" },
        },
        {
          label: "批次号",
          prop: "alarmBatchNo",
          type: "select",
          options: [],
          optionKey: { label: "batchNo", value: "batchNo" },
        },
        {
          label: "病虫害类别",
          prop: "alarmTypeName",
          type: "select",
          options: [
            { label: "病害", value: 0 },
            { label: "虫害", value: 1 },
          ],
          optionKey: { label: "label", value: "label" },
        },
        {
          label: "记录日期",
          prop: "date",
          type: "daterange",
        },
      ],
      rules: {
        facilityNoList: [
          {
            required: true,
            message: "请选择种植设施",
            trigger: ["change", "blur"],
          },
        ],
        batchNo: [
          {
            required: true,
            message: "请选择批次",
            trigger: ["change", "blur"],
          },
        ],
        alarmTypeName: [
          { required: true, message: "请选择病虫害类别", trigger: "change" },
        ],
        alarmDes: [
          { required: true, message: "请选择病虫害名称", trigger: "change" },
        ],
        personNoList: [
          {
            required: true,
            message: "作业人不能为空",
            trigger: "change",
          },
        ],
        insectDate: [
          { required: true, message: "请选择处理日期", trigger: "change" },
        ],
      },
      useMedicineVisible: false, // 查看用药
      useMedicineList: [], // 用药列表
      isShow: false, // 添加dialog
      batchList: [], // 批次列表
      facilityLists: [],
      addActive: true,
      facilityDialogVisible: false,
      batchFacilityMapperList: [],
      showpicview: false,
      pictviewurl: "",
      newtotalSize: 0,
      farmingTypeTitles: farmingTypeTitle(),
      alarmTypeList: [
        { name: "病害", value: 0 },
        { name: "虫害", value: 1 },
      ],
      // 当前物联数据日期选择
      zhdateList: "",
      // 当前选中的病虫害图片id
      nowsectpictureid: "",
      state1: "",
      // 处理类别选择
      handingtypeList: [
        { name: "已处理", id: 1 },
        { name: "未处理", id: 2 },
      ],
      // 是否需要处理
      disposeActionList: [
        { name: "还未处理", id: 1 },
        { name: "是", id: 2 },
        { name: "否", id: 3 },
      ],
      isshowhandleview: false,
      handlemessage: {
        insectAlarmId: "",
        disposeAction: "", // 处理类别
        disposeFlag: "", // 是否需要处理
        insectDisposeDes: "", // 虫害处理信息
      },
      alarmDesList: [],
      // 可选择所有地块
      facilityList: [],
      // 所搜索框内容
      searchlist: {
        result: 2,
      },
      pickerOptionsone: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              picker.$emit("pick", new Date());
            },
          },
          {
            text: "昨天",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit("pick", date);
            },
          },
          {
            text: "一周前",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", date);
            },
          },
        ],
      },
      // 上传图片
      image1: "",
      image2: "",
      imgloading: false,
      handlerFormData: {
        disposeDate: "",
        insectDisposeDes: "",
      },
      idList: [],
      addFormData: {
        batchNo: "",
        alarmBatchNo: "",
        alarmBatchName: "",
        facilityNoList: [],
        batchSingleNos: [],
        alarmTypeName: "",
        alarmDes: "",
        remark: "",
        insectDate: "",
        disposeManNo: "",
        pictureId: "",
      },
      nowChanceStau: "",
      showIdNameList: false, //查看编号
      activeSingleNoList: [],
      singleNoList: [],
      showInfo: false, //详情
      inputsRecordBOList: [],
    };
  },
  computed: {
    ...mapGetters({
      judgePermission: "permission/judgePermission",
    }),
  },
  watch: {
    dialogFormVisible(v) {
      if (v) {
        this.$nextTick(() => {
          this.$refs.formData?.clearValidate();
        });
      }
    },
  },
  created() {
    this.getfacilityList();
    this.getTableDataList();
    this.getSelectDatalist();
  },
  methods: {
    // TODO:表格查询
    getTableDataList() {
      this.loading = true;
      this.tableData = [];
      let params = {
        page: this.currentPage,
        size: this.pageSize,
        sortList: this.sortList || [],
        entity: {
          alarmBatchNo: this.searchlist.alarmBatchNo || undefined,
          organizationNo: sessionStorage.getItem("organizationNo"),
          disposeAction: this.tableColumn === this.tableColumn2 ? 1 : 2,
          alarmTypeName: this.searchlist.alarmTypeName || undefined,
          isResolveSuccess: false,
          batchType: 'SINGLE'
        },
      };
      if (this.searchlist.date) {
        params.entity.startTime = new Date(this.searchlist.date[0]);
        params.entity.endTime = new Date(this.searchlist.date[1]);
      }
      this.entity = params.entity;
      API.getList(params).then((res) => {
        if (res.code === 1) {
        } else {
          this.$message.error("查询失败");
        }
        this.loading = false;
        let data = res.data;
        // 赋值总条数
        this.totalSize = data.totalElements;
        // 赋值数组
        this.tableData = data.content;
        this.addblankmet();
        this.resetActionBar();
      });
    },
    // TODO:获取下拉框数据
    async getSelectDatalist() {
      // 获取所有批次
      API.getAllBatchList({ batchType: "SINGLE",simpleData: true }).then((res) => {
        this.batchList = res.data;
        this.formConfig[0].options = res.data;
        this.formConfig[1].options = res.data;
      });
      danwei
        .getallunitlist({
          unitTypeNo: "995416607651037184",
          organizationNo: sessionStorage.organizationNo,
        })
        .then((res) => {
          this.unitlists = res.data;
        });
      let medicineList = await API.getMedicineList();
      this.agriculturalMaterialList = medicineList.data;
      API.getEmployeeList().then((res) => {
        if (res.code !== 1) {
          return;
        }
        this.staffList = res.data;
        console.log(this.staffList);
      });
    },
    async batch(e) {
      this.facilityLists = []
      this.idList = []
      this.$set(this.addFormData,'facilityNoList',[])
      this.$set(this.addFormData,'batchSingleNos',[])
      // this.addFormData.facilityNoList = []
      // this.addFormData.batchSingleNos = []
      let res = await API.queryFacility(e);
      this.facilityLists = res.data;
      let result = await API.queryIdList(e);
      this.idList = result.data.singleNoList;
    },
    // TODO:
    // 图片地址
    ImageUrl() {
      return `${baseURL.webServiceUrl}v3/patrol/picture/addMultipart`;
    },
    handleResponse(res) {
      this.formData.disposePictureId = res.data;
      pestInfoApi.queryPicture(res.data).then((res) => {
        this.image2 = "data:image/png;base64," + res.data.pictureData;
        this.addFormData.pictureId = res.data.pictureId;
      });
      return this.image2;
    },
    handleRemove() {
      this.formData.disposePictureId = "";
      this.addFormData.pictureId = "";
      this.image2 = "";
    },
    // 点击查看
    clickLook() {
      console.log();
    },
    // 获取设施选择框数据
    getfacilityList() {
      userApi
        .getfacilityAll({
          organizationList: sessionStorage
            .getItem("organizationList")
            .split(","),
          farmingTypeNo: sessionStorage.getItem("farmingTypeNo"),
        })
        .then((res) => {
          this.facilityList = res.data;
        });
    },
    add() {
      this.alarmDesList = [];
      this.facilityLists = []
      this.nowChanceStau = "add";
      this.title = "添加";
      this.isShow = true;
      this.addFormData.alarmBatchNo = "";
      this.$nextTick(() => {
        this.addFormData = { ...this.addFormData };
        this.$refs.addFormData.resetFields();
      });
    },
    // 添加保存
    addSave() {
      this.$refs.addFormData.validate((valid) => {
        if (valid) {
          let params = { ...this.addFormData };
          params.inputsRecordBOList = [];
          this.assetQuantity.forEach((el, index) => {
            params.inputsRecordBOList.push({
              assetQuantity: el,
              materialNo: this.materialNos[index],
              exchangeRatio: this.exchangeRatio[index],
              exchangeUnitNo: this.exchangeUnitNo[index] || "",
              organizationNo: sessionStorage.getItem("organizationNo"),
            });
          });
          console.log(params);
          return;
        } else {
          return false;
        }
      });
    },
    addCancel() {
      this.isShow = false;
      this.materialNos = [];
      this.materialNum = 1;
      this.assetQuantity = [];
      this.exchangeRatio = [];
      this.exchangeUnitNo = [];
      this.addFormData = {};
      this.image2 = "";
    },
    // 导出
    async download() {
      let params = {
        entity: {
          ...this.entity,
        },
      };
      let url = "v3/patrol/insectAlarm/download";
      let excel = this.farmingTypeTitles + "记录表";
      this.downloadExcel(url, params, excel);
    },
    search() {
      this.currentPage = 1;
      this.getTableDataList();
    },
    changePageSize(pageSize) {
      this.pageSize = pageSize;
      this.getTableDataList();
    },
    changeCurrentPage(currentPage) {
      this.currentPage = currentPage;
      this.getTableDataList();
    },
    // 处理
    handle(e) {
      // console.log(e);
      this.nowChanceStau = "edit";
      this.titleText = "编辑";
      this.dialogFormVisible = true;
      this.canInput = true;
      this.addActive = false;
      this.delActive = false;
      this.saveActive = true;
      this.editActive = false;
    },
    // 处理确认
    handleSave() {
      this.$refs.handlerFormData.validate((valid) => {
        if (valid) {
          console.log(this.handlerFormData, this.image2);
          return;
        } else {
          return false;
        }
      });
    },
    // 添加药品
    addMaterial() {
      this.materialNum++;
    },
    // 已完成--未完成
    batchstaumet(i) {
      if (i === 0) {
        this.tableColumn = this.tableColumn1;
        this.addActive = true;
      } else {
        this.tableColumn = this.tableColumn2;
        this.addActive = false;
      }
      this.getTableDataList();
    },
    // 添加
    addSaves() {
      this.$refs.addFormData.validate(async (valid) => {
        if (valid) {
          let params = { ...this.addFormData };
          this.batchList.forEach((el) => {
            if (el.batchNo === this.addFormData.batchNo) {
              params["alarmBatchName"] = el.batchName;
            }
          });
          // if(this.addFormData.alarmTypeName) {
          //   params.alarmTypeName =
          //   this.alarmTypeList[this.addFormData.alarmTypeName].name;
          // }
          params.alarmBatchNo = this.addFormData.batchNo;
          params.disposeAction = 2;
          params.isResolveSuccess = false;
          params.disposeFlag = 2;
          if (this.nowChanceStau === "add") {
            // console.log(params,'添加'); return
            let res = await API.add(params);
            if (res.code === 1) {
              this.$message.success("添加成功");
              this.isShow = false;
              this.getTableDataList();
            } else {
              this.$message.error("添加失败");
            }
          } else {
            // console.log('edit',params); return
            let res = await API.edit(params);
            if (res.code === 1) {
              this.$message.success("修改成功！");
              this.getTableDataList();
              this.isShow = false;
            } else {
              this.$message.error("修改失败！");
            }
          }
        } else {
          return false;
        }
      });
    },
    // 修改
    async handleEdit(row) {
      let res = await API.queryFacility(row.alarmBatchNo);
      this.facilityLists = res.data;
      let ress = await pestInfoApi.queryAlarmName({alarmTypeName: row.alarmTypeName});
      this.alarmDesList = ress.data;
      if (row.pictureId) {
        let res = await API.queryPicture(row.pictureId);
        this.image2 = "data:image/png;base64," + res.data.pictureData;
      }
      this.addFormData = { ...row };
      this.nowChanceStau = "edit";
      // this.addFormData.batchSingleNos = [];
      this.batchSingleNos = [];
      this.$set(this.addFormData,'batchSingleNos',[])
      // 回显编号
      if (row.singleMappers) {
        row.singleMappers.forEach((el) => {
          let arr = []
          arr.push(el.singleNo)
          // this.$set(this.addFormData,'batchSingleNos',arr)
          this.addFormData.batchSingleNos.push(el.singleNo);
        });
      }
      this.addFormData.insectDate = new Date(row.insectDate).getTime();
      this.addFormData.batchNo = row.alarmBatchNo;
      this.isShow = true;
    },
    // 单个删除
    delSingle(row) {
      this.$confirm("此操作将永久删除该条数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        customClass: "myClass",
      })
        .then(async () => {
          let res = await API.del(row.insectAlarmId);
          if (res.code === 1) {
            this.$message.success("删除成功！");
            this.getTableDataList();
          } else {
            this.$message.error("删除失败！");
          }
        })
        .catch(() => {
          //
          this.$message("取消删除");
        });
    },
    // 批量删除
    delList() {},
    // 查病虫害名称
    async queryAlarmName(e) {
      this.alarmDesList = [];
      // this.addFormData.alarmDes = "";
      this.$set(this.addFormData,'alarmDes','')
      let params = {
        alarmTypeName: e,
      };
      let res = await pestInfoApi.queryAlarmName(params);
      this.alarmDesList = res.data;
    },
    // 查看设施
    checkFacility(row) {
      let list = [];
      if (row.facilityNoList) {
        row.facilityNoList.map((el) => {
          let index = this.facilityList.findIndex((ele) => {
            return el === ele.facilityNo;
          });
          list.push({
            facilityNo: el,
            facilityName: this.facilityList[index].facilityName,
          });
        });
      }
      this.batchFacilityMapperList = list;
      this.facilityDialogVisible = true;
    },
    // 查看编号
    async seeIdNameList(row) {
      // console.log(row); return
      this.showIdNameList = true;
      let res = await API.queryIdList(row.alarmBatchNo);
      this.singleNoList = res.data.singleNoList;
      this.activeSingleNoList = [];
      row.singleMappers.forEach((el) => {
        this.activeSingleNoList.push(el.singleNo);
      });
    },
    // 查看图片
    async lookPicture(row) {
      console.log(row, "wwhw");
      if (row.pictureId) {
        let res = await API.queryPicture(row.pictureId);
        this.pictviewurl = res.data.pictureData;
      }
      this.showpicview = true;
    },
    // 查看详情
    lookInfo(row) {
      this.inputsRecordBOList = row.inputsRecordBOList;
      this.inputsRecordBOList.forEach((el) => {
        API.queryPictureNo(el.pictureNo).then(async (res) => {
          el.url = "data:image/png;base64," + res.data.pictureData;
        });
      });
      setTimeout(() => {
        this.showInfo = true;
      }, 500);
    },
  },
};
</script>

<style scoped lang="scss">
.facility-list {
  display: flex;
  justify-content: flex-start;
  flex-direction: row;
  flex-wrap: wrap;
  .facility-item {
    width: 400px;
    max-width: 30%;
    min-width: 30%;
    margin-right: 3%;
    margin-bottom: 10px;
    // height: 80px;
    border-radius: 5px;
    // border: 1px solid #ccc;
    box-shadow: 1px 1px 10px rgba(0, 0, 0, 0.15);
    padding: 10px 20px;

    .info-line {
      display: flex;
      justify-content: flex-start;
      align-items: flex-start;
      font-size: 14px;
      &:not(:last-child) {
        margin-bottom: 10px;
      }
      .name {
        text-align: left;
        width: 80px;
        flex-shrink: 0;
      }
      .value {
        width: 100%;
        text-align: left;
        font-weight: normal;
      }
    }
  }
}
::v-deep .el-checkbox {
  .el-checkbox__label {
    color: #dbe9e9;
    color: #d3e01c;
    // flex-direction: column;
  }
}
::v-deep .el-dialog {
  .el-dialog__header .el-dialog__title {
    color: #dbe9e9;
  }
  background-color: #005d7b;
  border: #23fff8 1px solid;
  white-space: nowrap;
  ::v-deep .el-input__inner {
    color: #dbe9e9 !important;
  }
}
// ::v-deep .el-dialog .el-select .el-input__inner {
// color: #dbe9e9 !important;
// }

::v-deep .tab-select {
  width: 100%;
  .butt-list-sty {
    position: absolute;
    left: 5px;
    top: 7px;
  }
}
td {
  ::v-deep & > div {
    width: 100% !important;
  }
}
::v-deep .el-image__error {
  display: none;
}
::v-deep .el-upload__tip {
  display: none;
}
// 查看编号
.IdNameList {
  width: 120px;
  height: 33px;
  margin-right: 10px;
  color: #000;
  text-align: center;
  line-height: 33px;
  border: 1px solid #006e91;
}
.activeId {
  background-color: #006e91;
  color: #fff;
}
.info {
  margin-bottom: 10px;
  border-bottom: 1px dashed #ccc;
  .line {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 20px;
    font-size: 16px;
    .left {
      width: 50%;
      display: flex;
      align-items: center;
      .value {
        max-width: 70%;
        img {
          width: 100%;
        }
      }
    }
    .right {
      flex: 1;
      display: flex;
      align-items: center;
    }
  }
}
</style>
